package com.googlecode.tinyoutliner.constants;
/**
 * Line Endings to allow files to be generated with cross-platform settings
 * @author rrees
 *
 */
public enum LineEndings {
	MAC("\r"), UNIX("\n"), WINDOWS("\r\n"), DEFAULT("\n");
	
	private String lineEnding;
	
	public String getLineEnding() { return lineEnding; }
	
	/**
	 * String to LineEndings converter for backwards compatibility
	 * @param lineEnding the target line ending string
	 * @return The LineEndings object that matches the string or the default line ending if none match
	 */
	public static LineEndings getLineEndingForString(String lineEnding) {
		for (LineEndings ending : LineEndings.values()) {
			if (ending.getLineEnding().equals(lineEnding)) {
				return ending;
			}
		}
		return DEFAULT;
	}
	
	private LineEndings(String lineEnding){
		this.lineEnding = lineEnding;
	}
}
